from PyQt5.QtWidgets import QMainWindow, QWidget, QVBoxLayout, QTabWidget, QLabel

from news_2.src.main import store
from news_2.src.main.utils.my_ding_bot import get_bot
from news_2.src.main.views.poxy_view import ProxySettingsForm
from news_2.src.main.views.scheduler_view import SchedulerViewForm
from news_2.src.main.views.web_list_view import TableWithDataList


class MainWindow(QMainWindow):
    def __init__(self):
        super().__init__()
        # 1. 加载数据
        self.store = store.get_store()
        self.bot = get_bot()
        # 2 创建页面
        self.__init_ui()

    def __init_ui(self):
        # 创建 QTabWidget
        self.tab_widget = QTabWidget()
        self.setCentralWidget(self.tab_widget)

        # 创建第一个选项卡的页面
        self.create_index_tab()
        # 创建第二个选项卡的页面
        self.create_proxies_tab()

        # 将页面添加到选项卡控件中

        self.setGeometry(100, 100, 880, 600)

    def create_index_tab(self):
        page = QWidget()
        layout = QVBoxLayout()
        self.create_web_list_ui(layout)
        self.create_scheduled_time_ui(layout)
        page.setLayout(layout)
        self.tab_widget.addTab(page, "首页")

    def create_proxies_tab(self):
        page = QWidget()
        layout = QVBoxLayout()

        poxy = ProxySettingsForm()
        layout.addWidget(poxy)

        page.setLayout(layout)
        self.tab_widget.addTab(page, "网络代理设置")

    def create_scheduled_time_ui(self, layout):
        self.scheduler_form = SchedulerViewForm()
        layout.addWidget(self.scheduler_form)

    def create_web_list_ui(self, layout):
        self.table_widget = TableWithDataList(self.store)  # 请提供 'your_store' 的实际值
        self.table_widget.setMinimumHeight(400)  # 设置最小高度为 300 像素
        layout.addWidget(self.table_widget)


